/*
 * led7seg.c
 *
 * Created: 11/19/2011 10:38:43 AM
 *  Author: Thuy Duong
 */ 


#include <avr/io.h>
#include <util/delay.h>

/*
 * 
 * 	- LED connected to PORTB.2
 * 	- Switch connected to PORTD.2
 */


#ifndef F_CPU
#define F_CPU 16000000UL // or whatever may be your frequency
#endif
#include <avr/io.h>
#include <util/delay.h>  
// BCD for displaying number to 7 segment LED
char num[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
int k,led1,led2,led3;
// k is the value for display
// led1 is displayed in LED1
//led2 is displayed in LED2
//led3 is displayed in LED3
int main(void)
{ 
	
    while(1)
    {
	 led1 = k%10;   
	 led2 = k%100-k%10;
	 led2 = k/100;
     DDRB =0xFF; // Port B is set as output
	 DDRC =0x07; // pin 0th, 1st and 2nd are set as output
	 PORTC =0x01; // Turn on the LED1
	 PORTB = num[led1];// Display value led1 on LED1
	 _delay_ms(50);
	 PORTC =0x02; // Turn on the LED2
	 PORTB = num[led2];// Display value led2 on LED2
	 _delay_ms(50);
	  PORTC =0x04; // Turn on the LED3
	 PORTB = num[led3];// Display value led3 on LED3
	 _delay_ms(50);
	 k =k+1;
	 if(k==1000)
	 k=0;
    }
}